﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;

namespace HiStaff.Util
{
    public class SXml
    {
        private const string XMLMSGRESUORCES_TAG = "MsgResources";
        private const string MESSAGE_TAG = "Message";
        private const string MESSAGEID_ATR = "Id";

        public static string ReadMessageById(string urlSource, string idMessage)
        {
            XmlDocument xmlDoc = new XmlDocument();
            string rtnValue = idMessage;

            string MsgResourcePath = AppDomain.CurrentDomain.BaseDirectory + "\\" + urlSource;

            if (!File.Exists(MsgResourcePath))
                return rtnValue;

            xmlDoc.Load(MsgResourcePath);

            // Read Report Note by Id
            XmlNode rptNode = xmlDoc.SelectSingleNode(XMLMSGRESUORCES_TAG + "/" +
                                                   MESSAGE_TAG + "[@" + MESSAGEID_ATR + "='" + idMessage + "']");
            if (rptNode != null)
            {
                rtnValue = rptNode.InnerText;
            }

            return rtnValue;
        }
    }
}
